package com.coocaa.fileexplore.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.io.File;

/**
 * Created by XuZeXiao on 2017/4/13.
 */

public class CommonUtils {
    public static String getVersionCode(Context context) {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = null;
        try {
            packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        if (packageInfo != null)
            return String.valueOf(packageInfo.versionCode);

        return "";
    }

    public static String getParentUrl(String url) {
        String parentPath = "";
        try {
            File file = new File(url);
            parentPath = file.getParent();
        } catch (Exception e) {
            return "";
        }
        return parentPath;
    }
}
